import { ApiHideProperty, ApiProperty } from '@nestjs/swagger'
import { Column, Entity, OneToMany } from 'typeorm'
import { SoftCompleteEntity } from '~/common/entity/common.entity'
import { SubPlanEntity } from '../sub-plan/entities/sub-plan.entity'

@Entity({ name: 'c_main_plan' })
export class MainPlanEntity extends SoftCompleteEntity {
  @Column({ name: 'plan_id', comment: '计划ID, PL+yymmdd+000', unique: true })
  @ApiProperty({ description: '计划ID, PL+yymmdd+000' })
  planId: string

  @Column({ name: 'plan_name', comment: '计划名称' })
  @ApiProperty({ description: '计划名称' })
  planName: string

  @Column({ name: 'class_id', comment: '班级ID' })
  @ApiProperty({ description: '班级ID' })
  classId: string

  @Column({ name: 'mark', default: '', comment: '计划备注' })
  @ApiProperty({ description: '计划备注' })
  mark: string

  @Column({ name: 'progress', type: 'float', default: 0, comment: '计划进度' })
  @ApiProperty({ description: '计划进度，0-100的百分比' })
  progress: number

  @Column({ name: 'publish_at', type: 'datetime', nullable: true, comment: '发布时间' })
  @ApiProperty({ description: '发布时间' })
  publishAt: Date

  @Column({ name: 'complete_at', type: 'datetime', nullable: true, comment: '完成时间' })
  @ApiProperty({ description: '完成时间' })
  completeAt: Date

  @Column({ name: 'punch_start_at', type: 'datetime', nullable: true, comment: '打卡开始时间' })
  @ApiProperty({ description: '打卡开始时间' })
  punchStartAt: Date

  @ApiHideProperty()
  @OneToMany(() => SubPlanEntity, subPlan => subPlan.mainPlan)
  subPlans: SubPlanEntity[]
}
